package com.sun.common;

import lombok.AllArgsConstructor;
import lombok.Data;

/*
 * 返回前端统一数据的封装类
 * @author rabbiter
 * @date 2023/1/2 20:36
 */
@Data
@AllArgsConstructor
public class Result {

    private int code;  //编码 200/400
    private String msg;  //成功/失败
    private Long total;  //总记录数
    private Object data;  //数据

    public static Result fail() {
        return new Result(400, "失败", 0L, null);
    }

    public static Result fail(int code, String msg) {
        return new Result(code, msg, 0L, null);
    }

    public static Result success() {
        return new Result(200, "成功", 0L, null);
    }

    public static Result success(Object data) {
        return new Result(200, "成功", 0L, data);
    }

    public static Result success(Object data, Long total) {
        return new Result(200, "成功", total, data);
    }
}
